<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台主页模块 - XzcBlogTemplate后台管理</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/common.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/blogadd.css">
</head>
<body>
<div class="layui-container main">
    <div class="layui-row layui-col-space20">
        <div class="layui-col-md12">
            <p>
		        	<span class="layui-breadcrumb" style="visibility: visible;">
			          	<a href="bloglist.html">博客管理系统</a><span lay-separator="">/</span>
			          	<a href="bloglist.html">后台首页</a><span lay-separator="">/</span>
			          	<a><cite>博文编辑</cite></a>
		        	</span>
            </p>
        </div>
        <div class="layui-col-md12">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" id="t1" required lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input max_width500">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <select name="city" lay-verify="required" value=''>
                            <option value="" class="max_width500"></option>
                            <option value="Java基础" class="max_width500">Java基础</option>
                            <option value="数据库" class="max_width500">数据库</option>
                            <option value="JSP" class="max_width500">JSP</option>
                            <option value="框架" class="max_width500">框架</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">置顶</label>
                    <div>
                        <input id="置顶" type="checkbox" name="switch" value="true" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <textarea name="desc" placeholder="请输入文本内容" class="layui-textarea" id="editor"
                                  style="height: 500px"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo" id="button">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script src="static/js/jquery-1.12.4.min.js"></script>
<script src="static/layui/layui.all.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //1.窗体加载后，发送异步请求：
        var blogid = sessionStorage.getItem("blogid");
        $.get("Blog/selectByBlogid", {"blogid": blogid}, function (rs) {
            /*把文章标题在前端页面展示*/
            document.querySelector('input[name="title"]').setAttribute('value', rs[0].title);
            if (rs[0].status == 1) {
                $("#置顶").prop("checked", true);
            } else if (rs[0].status == 0) {
                $("#置顶").prop("checked", false);
            }
            $("[name='city']").val(rs[0].type);
            $("#editor").val(rs[0].detail);
        });
        /*修改数据并提交*/
        $("button[id='button']").click(function () {
            var t = $("[id='t1']").val();
            var type = $("[name='city']").val();
            var detail = $("[id='editor']").prop('value');
            var status = $("#置顶").prop("checked");
            if (status == true) {
                status = 1;
            } else if (status == false) {
                status = 0;
            }
            $.get("Blog/updateBlogTextById", {
                    "blogid": blogid,
                    "title": t,
                    "type": type,
                    "detail": detail,
                    "status": status
                },
                function () {
                    alert("修改成功！")
                    window.location.href="\"http://localhost:8080/main.html\""
                });
        });
    });
</script>
</html>